package bom.example.common.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.ValueFilter;

/**
 * @author X.I.O
 * @title: JsonUtils
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/29 17:46
 */
public class JsonUtils {

    public static Object nullDataDeal(Object data){
        ValueFilter filter = new ValueFilter() {
            @Override
            public Object process(Object obj, String s, Object v) {
                if(v==null){
                    return "";
                }
                return v;
            }
        };
        String json= JSON.toJSONString(data, filter);
        return JSON.parse(json);
    }

    public static String getString(Object data){
        return JSON.toJSONString(data);
    }

    public static Object getObject(String jsonStr){
        return JSON.parse(jsonStr);
    }

    public static <T> T getObject(String jsonStr,Class<T> cls){
        return JSON.parseObject(jsonStr,cls);
    }

    public static JSONObject getJSONObject(String jsonStr){
        return JSON.parseObject(jsonStr);
    }


}
